<?php use_helper('Pagination'); ?>

<?php   $util = new Util();
		$charset = $util->getCharset();
?>

<?php $accion='index' ?>
<?php $routeName = sfContext::getInstance()->getRouting()->getCurrentInternalUri(false) ?>

<?php $pager->getPage()?>

<h1>Lista de <?php echo $objDef['general']['labelPlural']?></h1>

<?php include_partial('search/searchBar',array( 'className' => $className, 'moduleRef' => $module, 'actionRef' => 'index'))?>


<?php echo pager_navigation($pager, $routeName.'?className='.$className) ?>

<?php if(!$objDef['general']['isReadOnly']):?>
<a href="<?php echo url_for($module.'/new?className='.$className) ?>"><img src="/images/icons/32/add.png" title="Nuevo "<?php echo $objDef['general']['labelSingular'];?>/></a>
<?php endif;?>

<table id="listTable">
  <thead>
    <tr>
       <th>Acciones</th>
    
    <?php foreach($objDef['attributes'] as $fieldName => $att):?>
      <?php if($att['list']):?>
      	<th><?php if($charset=='utf8'){echo $att['label']!='' ?  $att['label']:  $fieldName;}else{echo $att['label']!='' ?  utf8_decode($att['label']):  $fieldName;}?></th>
      <?php endif;?>
    <?php endforeach;?>  
    </tr>
  </thead>
  <tbody>
    <?php foreach ($pager->getResults() as $item): ?>
    <tr>
      <td width="112px"><?php  echo link_to('<img src="/images/icons/32/show.png"/>', $module. '/show?id='.$item->id.'&className='.$className);?>
      	  <?php if(!$objDef['general']['isReadOnly'])  echo link_to('<img src="/images/icons/32/edit.png"/>', $module.'/edit?id='.$item->id.'&className='.$className);?>
      	  <?php if($objDef['general']['canBeDeleted']) echo link_to('<img src="/images/icons/32/delete.png"/>', $module.'/delete?id='.$item->id.'&className='.$className);?>
      </td>
      <?php foreach($objDef['attributes'] as $fieldName => $att):?>
    	  <?php if($att['list']):?>
    	  <td>
    	    <?php if($att['type']=='BO'):?>
    	    	
    	    	<?php if($item->getTable()->hasRelation($fieldName)){
    	    		$fieldName2 = $fieldName.'_id';
    	    		if($item->$fieldName2!=''){
	    	    		$classname = $item->$fieldName->getTable()->getOption('name');
	    	    		$relatedObjDef = $util->getOEDef($classname);
	    	    		if($relatedObjDef){
		    	    		$descriptor = $relatedObjDef['general']['descriptor'];
		    	    		echo $item->$fieldName->$descriptor;
	    	    		}else{
    	    				echo $item->$fieldName;
    	    			}
    	    		}
    	    	} ?>
    	    <?php elseif($att['type']=='boolean'):?>
    	    	<?php echo $item->$fieldName ? 'true': 'false';?>
            <?php elseif($att['type']=='image'):?>
    	    	<?php if($item->$fieldName!=''):?>
    	    		<img src="<?php echo '../'.str_replace("\"","/",sfConfig::get('sf_icons_dir_name')).'/'.$item->$fieldName ?>" alt="<?php echo $item->$fieldName?>" />
    	    	<?php endif;?>
            <?php elseif($att['type']=='file'):?>
				  <?php include_partial('renderFile', array('self' => $item,'fieldName' => $fieldName, 'label' => '', 'origin' => 'upload')) ?>
    	    <?php else:?>
      			<?php echo $item->$fieldName;?>
      		<?php endif;?>
      		</td>
      <?php endif;?>
      <?php endforeach;?>
      <?php //echo utf8_encode($cliente->persona->nombre) ?>
    </tr>
    <?php endforeach; ?>
  </tbody>
</table>
